package com.wsoft.cms.job;

import com.wsoft.cms.entity.CmsAnnouncementEntity;
import com.wsoft.cms.manager.CmsAnnouncementManager;
import com.wsoft.core.context.AuthLoginModeContextHolder;
import com.wsoft.enums.PublishStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author z001
 * @Date 2025/1/10 10:07
 */
@Slf4j
@Service
public class PublishJob implements Job {
    @Resource
    private CmsAnnouncementManager announcementManager;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<CmsAnnouncementEntity> annoList = announcementManager.getPublishAnno();
        for (CmsAnnouncementEntity entity : annoList) {
            entity.setSendStatus(PublishStatusEnum.PUBLISH.getType());
        }
        AuthLoginModeContextHolder.need();
        announcementManager.updateBatchById(annoList);
    }
}
